# -*- coding: utf-8 -*-


import os
# redis 表名
# 任务表模版
TAB_REQUSETS = "{redis_key}:z_requsets"
# 任务失败模板
TAB_FAILED_REQUSETS = "{redis_key}:z_failed_requsets"
# 爬虫状态表模版
TAB_SPIDER_STATUS = "{redis_key}:z_spider_status"
# item 表模版
TAB_ITEM = "{redis_key}:s_{item_name}"
# 爬虫时间记录表
TAB_SPIDER_TIME = "{redis_key}:h_spider_time"

# MYSQL
MYSQL_IP = os.getenv("MYSQL_IP")
MYSQL_PORT = int(os.getenv("MYSQL_PORT", 3306))
MYSQL_DB = os.getenv("MYSQL_DB")
MYSQL_USER_NAME = os.getenv("MYSQL_USER_NAME")
MYSQL_USER_PASS = os.getenv("MYSQL_USER_PASS")

# MONGODB
MONGO_IP = os.getenv("MONGO_IP", "localhost")
MONGO_PORT = int(os.getenv("MONGO_PORT", 27017))
MONGO_DB = os.getenv("MONGO_DB")
MONGO_USER_NAME = os.getenv("MONGO_USER_NAME")
MONGO_USER_PASS = os.getenv("MONGO_USER_PASS")

# 项目地址
DIR_PATH = os.path.abspath(os.path.dirname(__file__))
# 超时
DOWNLOAD_TIMEOUT = 10
# 重试延时
RETRY_DELAY = 0
# 爬虫的并发数量
CONCURRENT_REQUESTS = 5
# 爬虫任务
CONCURRENT_TASK_MAX = 32

# 日志
LOG_ENABLED = True  # 是否开启日志
LOG_TO_CONSOLE = True  # 是否输出到控制台
LOG_FILE = "spider.log"  # 日志文件
LOG_LEVEL = "info"  # 日志等级
LOG_FORMAT = '%(levelname)s - %(asctime)s - process: %(process)d - %(filename)s - %(name)s - %(lineno)d - %(module)s - %(message)s'  # 日志格式
DEFAULT_REQUEST_HEADERS = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36'
}
# 去除控制台多余调试信息
RETRY_ENABLED = True  # 是否开启重试
RETRY_TIMES = 3  # 重试次数3次

# 状态码限制
STATUS_CODE_CONFIG = True
STATUS_CODE_FORBID = []
# REDIS配置
REDIS_HOST = "127.0.0.1"
REDIS_PORT = "6379"
